package com.jacklin.product.controller;

import com.jacklin.product.domain.Product;
import com.jacklin.product.service.ProductService;
import org.jacklin.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 库存服务控制层
 *
 * @author: jacklin
 * @date: 2022/8/4 9:20
 **/
@RestController
@RequestMapping(value = "/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 扣减库存
     *
     * @author: jacklin
     * @date: 2022/8/4 9:20
     **/
    @RequestMapping(value = "reduceStock")
    public Boolean reduceStock(@RequestParam(value = "id") Integer id, @RequestParam(value = "amount") Integer amount) {
        return productService.reduceStock(id, amount);
    }


    /**
     * 根据id查询商品以及库存信息
     *
     * @author: jacklin
     * @date: 2022/8/4 9:18
     **/
    @RequestMapping(value = "/getById")
    public Result<?> getById(@RequestParam String id) {
        return Result.OK(productService.getById(id));
    }

    /**
     * 更新商品信息
     *
     * @author: jacklin
     * @date: 2022/8/4 9:18
     **/
    @RequestMapping(value = "/updateById")
    public Result<?> updateById(@RequestBody Product product) {
        return Result.OK(productService.updateById(product));
    }
}
